package cn.stylefeng.guns.modular.controller;


import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.entity.GuideImg;
import cn.stylefeng.guns.modular.service.IGuideImgService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 启动页 引导页表 前端控制器
 * </p>
 *
 * @author XiangTianGe
 * @since 2020-04-15
 */
@Controller
@RequestMapping("/guide")
public class GuideImgController extends BaseController {

    @Autowired
    private IGuideImgService iGuideImgService;

    private static String PREFIX = "/guide/";

    @RequestMapping
    public ModelAndView index() {
        ModelAndView index = iGuideImgService.index();
        index.setViewName(PREFIX + "guide.html");
        return index;
    }

    @RequestMapping("add")
    public ModelAndView add() {
        ModelAndView index = iGuideImgService.add();
        index.setViewName(PREFIX + "guide_add.html");
        return index;
    }

    @RequestMapping("edit/{id}")
    public ModelAndView add(@PathVariable Long id) {
        ModelAndView index = iGuideImgService.edit(id);
        index.setViewName(PREFIX + "guide_edit.html");
        return index;
    }

    /**
     * 列表
     */
    @ResponseBody
    @RequestMapping("list")
    public LayuiPageInfo list(Integer type) {
        //获取分页参数
        Page page = LayuiPageFactory.defaultPage();

        return iGuideImgService.getList(type, page);
    }


    /**
     * 新增
     */
    @RequestMapping("add-guide")
    @ResponseBody
    public ResponseData add(@RequestBody GuideImg guideImg) {
        iGuideImgService.add(guideImg);
        return SUCCESS_TIP;
    }

    /**
     * 新增
     */
    @RequestMapping("edit-guide")
    @ResponseBody
    public ResponseData edit(@RequestBody GuideImg guideImg) {
        iGuideImgService.update(guideImg);
        return SUCCESS_TIP;
    }

    @RequestMapping("delete/{id}")
    @ResponseBody
    public ResponseData delete(@PathVariable Long id) {
        iGuideImgService.delete(id);
        return SUCCESS_TIP;
    }
}

